
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.*;

/**
 * CompilerException class, based on the CalcException class
 * which is thrown by the compiler when scoping or type errors occur
 * @author Keith Davelaar
 * @version 2012.05.06
 */
public class CompilerException extends RecognitionException {
    
	/** Message which contains the error */
	private String msg;
    /** for Serializable */
	public static final long serialVersionUID = 24162462L; 
    
	/**
	 * Constructor, which only requires the error message to be printed
	 * @param msg The error message to be printend
	 */
    public CompilerException(String msg) {
        super();
        this.msg = msg;
    }

    /***
     * Constructor that takes a node of the AST tree (i.e. IDENTIFIER) and
     * the error message to build a more informative error message.
     * @param tree The tree in which the error occurs
     * @param msg The message to be printed
     */
    public CompilerException(Tree tree, String msg) {
        super();
        this.msg = tree.getText() + 
                   " (" + tree.getLine() + 
                   ":" + tree.getCharPositionInLine() + 
                   ") " + msg;
    }

    /** Get the error message  
     * @return The error message
     */
    public String getMessage(){ return msg; }
}